﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Weight.Controls
{
    public class LYFLabel : Label
    {
        public LYFLabel()
        {
            this.SetStyle(
                 //ControlStyles.UserPaint |//使用自定义的绘制方式
                 ControlStyles.ResizeRedraw//当控件大小发生变化时就重新绘制
                | ControlStyles.SupportsTransparentBackColor//则控件接受 alpha 组件数小于 255 个的 BackColor 来模拟透明度
                | ControlStyles.AllPaintingInWmPaint//则控件忽略窗口消息 WM_ERASEBKGND 以减少闪烁
                | ControlStyles.OptimizedDoubleBuffer//则控件将首先绘制到缓冲区而不是直接绘制到屏幕，这可以减少闪烁
                , true);
        }

        private bool _isSetSkin = true;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DefaultValue(typeof(bool), "true")]
        public bool IsSetSkin { get => _isSetSkin; set => _isSetSkin = value; }

        public void SetSkin(Color color)
        {
            if (!_isSetSkin) return;
            if (this.BackColor != Color.Transparent)
                this.BackColor = color;
            else
                this.ForeColor = color;
        }
    }
}
